﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xarmarin.GoldFinger.ApplicationCore;
using Xarmarin.GoldFinger.Engine.Core;
using Xarmarin.GoldFinger.Interface;

namespace Xarmarin.GoldFinger.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class LoginPage : ContentPage
    {
        public LoginPage()
        {
            InitializeComponent();
            BackgroundImage = "timg.jpg";
            //验证用户是否存在
            if (!Initializer.ApplicationInit_Start())
            {
                btn_Continue.IsVisible = false;
            }
            DependencyService.Get<IToast>().ShortAlert("欢迎来到仙门");
        }

        private void Btn_Start_Click(object sender, EventArgs e)
        {
            Application.Current.MainPage = new NavigationPage(SinglePageManager.MainPage);
        }
        private void Btn_StartNew_Click(object sender, EventArgs e)
        {
            Application.Current.MainPage = SinglePageManager.CreateSubjectPage;
        }
        private void ButtonData_Clicked(object sender, EventArgs e)
        {
            Application.Current.MainPage = new NavigationPage(SinglePageManager.SubListPage);

        }
        private async void ButtonReBuild_Clicked(object sender, EventArgs e)
        {
           
            var r = await DisplayAlert("天道示警", "确定要清除所有因果吗(游戏出错时请清除)", "我意已决", "容后再议");
            if (r)
            {
                btn_Continue.IsVisible = false;
                Engine.DbMigration.DefaultMigration.CleanDb();
            }
        }

        private async void ImageButton_ClickedAsync(object sender, EventArgs e)
        {
            var r=
                await DisplayAlert("提示", "确定要退出吗", "确定", "取消");
            if (r)
            {
                DependencyService.Get<IXamBase>().CloseApp();
            }
        }
    }
}